package com.zzyy.study.listener;

import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * Description:
 * <p>
 * ClassName: RedisKeyExpirationListener
 * date: 2021/2/17 16:46
 *
 * @author zzjx
 * @version 1.0
 * @since JDK 1.8
 */
@Component
public class RedisKeyExpirationListener extends KeyExpirationEventMessageListener {
    public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) {
        super(listenerContainer);
    }
    @Override
    public void onMessage(Message message, byte[] pattern) {
        String expireKey_Token = message.toString();
        System.out.println("过了10秒钟到了，过期key:"+expireKey_Token);
        //暂停毫秒，由于redis的数据还没有传递回来，程序跑的太快
        try {
            TimeUnit.MILLISECONDS.sleep(300);
        }catch (InterruptedException e){
            e.printStackTrace();
        }
        //过期超时订单走向
    }
}
